<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    template="layout/templatePainelControle.xhtml">

	<ui:define name="body">
	
		<h2 class="title"><a href="#">Painel de Controle</a></h2><br/>
		
			<h:messages id="messages" globalOnly="true" styleClass="message"
				    errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"
				    rendered="#{showGlobalMessages != 'false'}"/>

			<h:form id="listEmpresasForm">
		        <rich:dataTable value="#{painelControleController.listaEmpresasValidade}" var="_emp"
		        	rows="30"
		        	id="tabelaEmpresas">
		        
		        	<rich:column style="background-color:#{painelControleController.recuperaCorBackground(_emp)}">
		        		<f:facet name="header">
		        			<h:selectBooleanCheckbox value="#{painelControleController.selecionadoTodos}">
		        				<a:support event="onchange" action="#{painelControleController.selecionaTodosPainel()}"
		        					reRender="tabelaEmpresas"/>
		        			</h:selectBooleanCheckbox>	
		        		</f:facet>
		        		<h:selectBooleanCheckbox value="#{_emp.selecionado}"/>
		        	</rich:column>
		        	
		        	<rich:column filterBy="#{_emp.dscRazaoSocial}" filterEvent="onkeyup" style="background-color:#{painelControleController.recuperaCorBackground(_emp)}">
		        		<f:facet name="header">Razão Social</f:facet>
		        		<h:outputText value="#{_emp.dscRazaoSocial}"/>
		        		<a:queue ignoreDupResponses="true"/>
		        		<rich:toolTip followMouse="true" direction="top-right" showDelay="500"
							styleClass="tooltip" layout="block">
							<span style="white-space: nowrap">
								<table>
									<tr>
										<td>
											<strong>Email:</strong><h:outputText value="#{_emp.dscEmail}"/><br/> 
											<strong>Data de Cadastro:</strong><h:outputText value="#{_emp.dtaCadastro}"><s:convertDateTime pattern="dd/MM/yyyy"/></h:outputText><br/>
											<strong>Telefone 1:</strong><h:outputText value="#{_emp.dscTelefone1}" /><br/>
											<strong>Telefone 2:</strong><h:outputText value="#{_emp.dscTelefone2}" /><br/>
											<strong>Endereço:</strong><h:outputText value="#{_emp.dscEndereco}" /><br/>
											<strong>Cidade:</strong><h:outputText value="#{_emp.dscCidade}" /><br/>
											<strong>UF:</strong><h:outputText value="#{_emp.dscUf}" /><br/>
											<strong>CEP:</strong><h:outputText value="#{_emp.dscCep}" converter="conversorCEP"/><br/>
											<strong>Nome Responsável:</strong><h:outputText value="#{_emp.dscNomeResponsavel}"/><br/>
											<strong>CPF Responsável:</strong><h:outputText value="#{_emp.dscCpfResponsavel}" converter="conversorCPF"/>
										</td>
									</tr>
								</table> 
							</span>
						</rich:toolTip>
		        	</rich:column>
		        	
		        	<rich:column filterBy="#{_emp.dscNomeFantasia}" filterEvent="onkeyup" style="background-color:#{painelControleController.recuperaCorBackground(_emp)}">
		        		<f:facet name="header">Nome Fantasia</f:facet>
		        		<h:outputText value="#{_emp.dscNomeFantasia}"/>
		        		<a:queue ignoreDupResponses="true"/>
		        		<rich:toolTip followMouse="true" direction="top-right" showDelay="500"
							styleClass="tooltip" layout="block">
							<span style="white-space: nowrap">
								<table>
									<tr>
										<td>
											<strong>Email:</strong><h:outputText value="#{_emp.dscEmail}"/><br/> 
											<strong>Data de Cadastro:</strong><h:outputText value="#{_emp.dtaCadastro}"><s:convertDateTime pattern="dd/MM/yyyy"/></h:outputText><br/>
											<strong>Telefone 1:</strong><h:outputText value="#{_emp.dscTelefone1}" /><br/>
											<strong>Telefone 2:</strong><h:outputText value="#{_emp.dscTelefone2}" /><br/>
											<strong>Endereço:</strong><h:outputText value="#{_emp.dscEndereco}" /><br/>
											<strong>Cidade:</strong><h:outputText value="#{_emp.dscCidade}" /><br/>
											<strong>UF:</strong><h:outputText value="#{_emp.dscUf}" /><br/>
											<strong>CEP:</strong><h:outputText value="#{_emp.dscCep}" converter="conversorCEP"/><br/>
											<strong>Nome Responsável:</strong><h:outputText value="#{_emp.dscNomeResponsavel}"/><br/>
											<strong>CPF Responsável:</strong><h:outputText value="#{_emp.dscCpfResponsavel}" converter="conversorCPF"/>
										</td>
									</tr>
								</table> 
							</span>
						</rich:toolTip>
		        	</rich:column>
		        	
		        	<rich:column filterBy="#{_emp.dscCnpj}" filterEvent="onkeyup" style="background-color:#{painelControleController.recuperaCorBackground(_emp)}">
		        		<f:facet name="header">CNPJ</f:facet>
		        		<h:outputText value="#{_emp.dscCnpj}"
		        			converter="conversorCnpj"/>
		        		<a:queue ignoreDupResponses="true"/>
		        		<rich:toolTip followMouse="true" direction="top-right" showDelay="500"
							styleClass="tooltip" layout="block">
							<span style="white-space: nowrap">
								<table>
									<tr>
										<td>
											<strong>Email:</strong><h:outputText value="#{_emp.dscEmail}"/><br/> 
											<strong>Data de Cadastro:</strong><h:outputText value="#{_emp.dtaCadastro}"><s:convertDateTime pattern="dd/MM/yyyy"/></h:outputText><br/>
											<strong>Telefone 1:</strong><h:outputText value="#{_emp.dscTelefone1}" /><br/>
											<strong>Telefone 2:</strong><h:outputText value="#{_emp.dscTelefone2}" /><br/>
											<strong>Endereço:</strong><h:outputText value="#{_emp.dscEndereco}" /><br/>
											<strong>Cidade:</strong><h:outputText value="#{_emp.dscCidade}" /><br/>
											<strong>UF:</strong><h:outputText value="#{_emp.dscUf}" /><br/>
											<strong>CEP:</strong><h:outputText value="#{_emp.dscCep}" converter="conversorCEP"/><br/>
											<strong>Nome Responsável:</strong><h:outputText value="#{_emp.dscNomeResponsavel}"/><br/>
											<strong>CPF Responsável:</strong><h:outputText value="#{_emp.dscCpfResponsavel}" converter="conversorCPF"/>
										</td>
									</tr>
								</table> 
							</span>
						</rich:toolTip>
		        	</rich:column>
		        	
		        	<rich:column filterEvent="onkeyup" style="background-color:#{painelControleController.recuperaCorBackground(_emp)}">
		        		<f:facet name="header">Data de Validade</f:facet>
		        		<rich:calendar value="#{_emp.dtaValidade}"
		        			datePattern="dd/MM/yyyy"
		        			enableManualInput="true"
		        			oninputkeypress="Mascara(this,Data);"
		        			oninputkeyup="Mascara(this,Data);"/>
		        		<a:queue ignoreDupResponses="true"/>
		        		<rich:toolTip followMouse="true" direction="top-right" showDelay="500"
							styleClass="tooltip" layout="block">
							<span style="white-space: nowrap">
								<table>
									<tr>
										<td>
											<strong>Email:</strong><h:outputText value="#{_emp.dscEmail}"/><br/> 
											<strong>Data de Cadastro:</strong><h:outputText value="#{_emp.dtaCadastro}"><s:convertDateTime pattern="dd/MM/yyyy"/></h:outputText><br/>
											<strong>Telefone 1:</strong><h:outputText value="#{_emp.dscTelefone1}" /><br/>
											<strong>Telefone 2:</strong><h:outputText value="#{_emp.dscTelefone2}" /><br/>
											<strong>Endereço:</strong><h:outputText value="#{_emp.dscEndereco}" /><br/>
											<strong>Cidade:</strong><h:outputText value="#{_emp.dscCidade}" /><br/>
											<strong>UF:</strong><h:outputText value="#{_emp.dscUf}" /><br/>
											<strong>CEP:</strong><h:outputText value="#{_emp.dscCep}" converter="conversorCEP"/><br/>
											<strong>Nome Responsável:</strong><h:outputText value="#{_emp.dscNomeResponsavel}"/><br/>
											<strong>CPF Responsável:</strong><h:outputText value="#{_emp.dscCpfResponsavel}" converter="conversorCPF"/>
										</td>
									</tr>
								</table> 
							</span>
						</rich:toolTip>
		        	</rich:column>
		        	
		        	<rich:column filterBy="#{_emp.tpoPlano}" filterEvent="onkeyup" style="background-color:#{painelControleController.recuperaCorBackground(_emp)}">
		        		<f:facet name="header">Plano</f:facet>
		        		<h:outputText value="#{_emp.tpoPlano}"/>
		        		<a:queue ignoreDupResponses="true"/>
		        		<rich:toolTip followMouse="true" direction="top-right" showDelay="500"
							styleClass="tooltip" layout="block">
							<span style="white-space: nowrap">
								<table>
									<tr>
										<td>
											<strong>Email:</strong><h:outputText value="#{_emp.dscEmail}"/><br/> 
											<strong>Data de Cadastro:</strong><h:outputText value="#{_emp.dtaCadastro}"><s:convertDateTime pattern="dd/MM/yyyy"/></h:outputText><br/>
											<strong>Telefone 1:</strong><h:outputText value="#{_emp.dscTelefone1}" /><br/>
											<strong>Telefone 2:</strong><h:outputText value="#{_emp.dscTelefone2}" /><br/>
											<strong>Endereço:</strong><h:outputText value="#{_emp.dscEndereco}" /><br/>
											<strong>Cidade:</strong><h:outputText value="#{_emp.dscCidade}" /><br/>
											<strong>UF:</strong><h:outputText value="#{_emp.dscUf}" /><br/>
											<strong>CEP:</strong><h:outputText value="#{_emp.dscCep}" converter="conversorCEP"/><br/>
											<strong>Nome Responsável:</strong><h:outputText value="#{_emp.dscNomeResponsavel}"/><br/>
											<strong>CPF Responsável:</strong><h:outputText value="#{_emp.dscCpfResponsavel}" converter="conversorCPF"/>
										</td>
									</tr>
								</table> 
							</span>
						</rich:toolTip>
		        	</rich:column>
		        	
		        	<rich:column style="background-color:#{painelControleController.recuperaCorBackground(_emp)}">
		        		<f:facet name="header">Pagamentos</f:facet>
		        		<h:commandLink value="DETALHAR" action="#{painelControleController.inicializarPopupPagamentos(_emp)}" 
		        			onclick="#{rich:component('carregando')}.show()"/>
		        	</rich:column>
		        	
		        </rich:dataTable>
		        <rich:datascroller for="tabelaEmpresas" renderIfSinglePage="false"/>
		        
		        <br/>
	            <div class="actionButtons">
		        	<h:commandButton id="remove" value="Excluir" action="#{painelControleController.excluir}"	
		        		onclick="javascript:if(!confirm('Tem certeza que deseja excluir?'))return false;"/>
		        	<h:commandButton id="save" value="Salvar" action="#{painelControleController.salvarTodasEmpresas()}"
		        		onclick="javascript:if(!confirm('Tem certeza que deseja salvar?'))return false;#{rich:component('carregando')}.show()"/>
		        	<h:commandButton id="email" value="Enviar E-mail" action="#{painelControleController.inicializarPopupEmail()}"/>
		        	<h:commandButton id="criarRacas" value="Criar Raças" action="#{painelControleController.criarRacasEmpresas()}"
		        		onclick="javascript:if(!confirm('Tem certeza que deseja criar as raças?'))return false;#{rich:component('carregando')}.show()"/>
		        </div>
	        </h:form>
		
		<rich:modalPanel id="modalEnviarEmail" height="480" width="700"
			showWhenRendered="#{painelControleController.exibePopupEmail}">
           	<f:facet name="header">
	            <h:panelGroup>
	                <h:outputText value="Enviar E-mail"></h:outputText>
	            </h:panelGroup>
	        </f:facet>
	        <f:facet name="controls">
	            <h:panelGroup>
	            	<h:form>
		                <h:commandButton image="/img/close.png" id="hidelinkServ"
		                	action="#{painelControleController.fechaPopupEmail()}"/>
                	</h:form>
	            </h:panelGroup>
	        </f:facet>

			<h:form id="enviarEmailForm" enctype="multipart/form-data">
				<h:messages id="messages" globalOnly="true" styleClass="message"
				    errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"
				    rendered="#{showGlobalMessages != 'false'}"/>
				    
				<table width="100%">
					<tr valign="top">
						<th align="center">
							Templates
						</th>
						<th align="center">
							E-mail
						</th>
					</tr>
					<tr>
						<td valign="top">
							<h:commandLink value="1. Aviso Validade" 
								action="#{painelControleController.selecionaTemplate(1)}"
								onclick="#{rich:component('carregando')}.show()"/><br/>
							<h:commandLink value="2. Validade Renovada" 
								action="#{painelControleController.selecionaTemplate(2)}"
								onclick="#{rich:component('carregando')}.show()"/><br/>
							<h:commandLink value="3. Validade Expirada" 
								action="#{painelControleController.selecionaTemplate(3)}"
								onclick="#{rich:component('carregando')}.show()"/><br/>
							<h:commandLink value="4. Boas vindas e manual" 
								action="#{painelControleController.selecionaTemplate(4)}"
								onclick="#{rich:component('carregando')}.show()"/><br/>
							<h:commandLink value="5. Em branco" 
								action="#{painelControleController.selecionaTemplate(5)}"
								onclick="#{rich:component('carregando')}.show()"/><br/>
							<h:commandLink value="6. Somente imagem" 
								action="#{painelControleController.selecionaTemplate(6)}"
								onclick="#{rich:component('carregando')}.show()"/><br/>
							<h:commandLink value="7. Manutenção programada" 
								action="#{painelControleController.selecionaTemplate(7)}"
								onclick="#{rich:component('carregando')}.show()"/>
						</td>
						<td>
							<h:panelGrid columns="1">
								<s:decorate template="/layout/edit.xhtml">
									<ui:define name="label">Assunto:</ui:define>
									<h:inputText value="#{painelControleController.assunto}" 
										style="width: 350px;"/>
								</s:decorate>
								
								<s:decorate template="/layout/edit.xhtml">
									<ui:define name="label">Corpo do e-mail:</ui:define>
									<rich:editor width="290" height="270"
										theme="advanced"
										value="#{painelControleController.texto}"/>
									<h:inputTextarea value="#{painelControleController.texto}" cols="40"
										rendered="false"
										rows="15"/>
								</s:decorate>
								
								<s:decorate template="/layout/edit.xhtml">
									<ui:define name="label">Anexo (Imagem):</ui:define>
									<s:fileUpload id="uploadFile" data="#{painelControleController.uploadedFile}"
										fileName="#{painelControleController.pictureName}"
										contentType="#{painelControleController.contentType}"
										fileSize="#{painelControleController.size}"
										accept="images/*"/>
								</s:decorate>
							</h:panelGrid>
						</td>
					</tr>
				</table>
				 <div class="actionButtons" align="center">
		        	<h:commandButton id="send" value="Enviar" action="#{painelControleController.enviarEmail()}"	
		        		onclick="javascript:if(!confirm('Tem certeza que deseja enviar?'))return false;#{rich:component('carregando')}.show()"/>
				</div>
			</h:form>
		</rich:modalPanel>
		
		<rich:modalPanel id="modalPagamentos" height="330" width="500"
			showWhenRendered="#{painelControleController.exibePopupPagamentos}">
           	<f:facet name="header">
	            <h:panelGroup>
	                <h:outputText value="Pagamentos"></h:outputText>
	            </h:panelGroup>
	        </f:facet>
	        <f:facet name="controls">
	            <h:panelGroup>
	            	<h:form>
		                <h:commandButton image="/img/close.png" id="hidelinkServ"
		                	onclick="#{rich:component('carregando')}.show()"
		                	action="#{painelControleController.fechaPopupPagamentos()}"/>
                	</h:form>
	            </h:panelGroup>
	        </f:facet>

			<h:form id="pagamentosForm">
				<rich:dataGrid value="#{painelControleController.listaPagamentos}"
					var="_pag"
		      		columns="1"
		      		elements="1">
		      		<rich:panel>
						<h:panelGrid columns="1">
							<s:decorate template="/layout/edit.xhtml">
								<ui:define name="label">Página <u>#{painelControleController.listaPagamentos.indexOf(_pag)+1}</u> de #{painelControleController.listaPagamentos.size()}</ui:define>
							</s:decorate>
							
							<s:decorate template="/layout/edit.xhtml">
								<ui:define name="label">Código de barras:</ui:define>
								<h:outputText value="#{_pag.dscCodBarras}" />
							</s:decorate>
							
							<s:decorate template="/layout/edit.xhtml">
								<ui:define name="label">Valor:</ui:define>
								R$ <h:outputText value="#{_pag.vlrPagamento}" converter="conversorMonetario" />
							</s:decorate>
							
							<s:decorate template="/layout/edit.xhtml">
								<ui:define name="label">Data Vencimento:</ui:define>
								<h:outputText value="#{_pag.dtaVencimento}">
									<s:convertDateTime pattern="dd/MM/yyyy"/>
								</h:outputText>
							</s:decorate>
							
							<s:decorate template="/layout/edit.xhtml">
								<ui:define name="label">Data Pagamento:</ui:define>
								<h:outputText value="#{_pag.dtaPagamento}">
									<s:convertDateTime pattern="dd/MM/yyyy"/>
								</h:outputText>
							</s:decorate>
							
							<s:decorate template="/layout/edit.xhtml">
								<ui:define name="label">Período Referência:</ui:define>
								<h:outputText value="#{_pag.dtaInicioRef}">
									<s:convertDateTime pattern="dd/MM/yyyy"/>
								</h:outputText>
								<h:outputText value=" a "/>
								<h:outputText value="#{_pag.dtaFimRef}">
									<s:convertDateTime pattern="dd/MM/yyyy"/>
								</h:outputText>
							</s:decorate>
						</h:panelGrid>
					
						<div align="center">
							<h:commandButton value="EXCLUIR" action="#{painelControleController.excluirPagamento(_pag)}" 
								onclick="javascript:if(!confirm('Tem certeza que deseja excluir?'))return false;#{rich:component('carregando')}.show()"/>
							<h:commandButton value="EDITAR" action="#{painelControleController.editarPagamento(_pag)}" 
								onclick="#{rich:component('carregando')}.show()"/>
						</div>
					</rich:panel>
					<f:facet name="footer">
						<rich:datascroller renderIfSinglePage="false"/>
					</f:facet>
				</rich:dataGrid>
				
				<div align="center">
					<h:commandButton value="NOVO" action="#{painelControleController.inicializarPopupNovoPagamento()}" 
						onclick="#{rich:component('carregando')}.show()"/>
				</div>
			</h:form>
		</rich:modalPanel>
		
		<rich:modalPanel id="modalNovoPagamento" height="300" width="550"
			showWhenRendered="#{painelControleController.exibePopupNovoPagamento}">
           	<f:facet name="header">
	            <h:panelGroup>
	                <h:outputText value="Novo Pagamento"></h:outputText>
	            </h:panelGroup>
	        </f:facet>
	        <f:facet name="controls">
	            <h:panelGroup>
	            	<h:form>
		                <h:commandButton image="/img/close.png" id="hidelinkServ"
		                	onclick="#{rich:component('carregando')}.show()"
		                	action="#{painelControleController.fechaPopupNovoPagamento()}"/>
                	</h:form>
	            </h:panelGroup>
	        </f:facet>

			<h:form id="novoPagamentoForm">
				<h:panelGrid columns="1">
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Empresa:</ui:define>
						<h:outputText value="#{painelControleController.pagamentoEdicao.empresa.dscNomeFantasia}" />
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Código de barras:</ui:define>
						<h:inputText value="#{painelControleController.pagamentoEdicao.dscCodBarras}" 
							maxlength="100"
							required="true"
							onkeydown="Mascara(this,Integer);"
							onkeyup="Mascara(this,Integer);"
							style="width: 250px;"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Valor:</ui:define>
						R$ <h:inputText value="#{painelControleController.pagamentoEdicao.vlrPagamento}"
							style="width:150px;"
							maxlength="10"
							required="true"
							converter="conversorMonetario" 
							onkeydown="Mascara(this,Valor);"
							onkeypress="Mascara(this,Valor);"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Data Vencimento:</ui:define>
						<rich:calendar value="#{painelControleController.pagamentoEdicao.dtaVencimento}"
		        			datePattern="dd/MM/yyyy"
		        			required="true"
		        			enableManualInput="true"
		        			oninputkeypress="Mascara(this,Data);"
		        			oninputkeyup="Mascara(this,Data);"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Data Pagamento:</ui:define>
						<rich:calendar value="#{painelControleController.pagamentoEdicao.dtaPagamento}"
		        			datePattern="dd/MM/yyyy"
		        			required="false"
		        			enableManualInput="true"
		        			oninputkeypress="Mascara(this,Data);"
		        			oninputkeyup="Mascara(this,Data);"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Período Referência:</ui:define>
						<rich:calendar value="#{painelControleController.pagamentoEdicao.dtaInicioRef}"
		        			datePattern="dd/MM/yyyy"
		        			required="true"
		        			enableManualInput="true"
		        			oninputkeypress="Mascara(this,Data);"
		        			oninputkeyup="Mascara(this,Data);"/>
						<h:outputText value=" a "/>
						<rich:calendar value="#{painelControleController.pagamentoEdicao.dtaFimRef}"
		        			datePattern="dd/MM/yyyy"
		        			required="true"
		        			enableManualInput="true"
		        			oninputkeypress="Mascara(this,Data);"
		        			oninputkeyup="Mascara(this,Data);"/>
					</s:decorate>
				</h:panelGrid>
					
				<div align="center">
					<h:commandButton value="Salvar" action="#{painelControleController.salvarPagamento()}" 
						onclick="javascript:if(!confirm('Tem certeza que deseja salvar?'))return false;#{rich:component('carregando')}.show()"/>
				</div>
			</h:form>
		</rich:modalPanel>
 	</ui:define>
</ui:composition>
